package com.mtsmda.java7features;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;

public class TryWithResources {

	public static void main(String[] args) {
		try(BufferedReader bufferedReader = new BufferedReader(new FileReader("mda.html"))){
			System.out.println(bufferedReader.readLine());
		}catch(IOException e){
			e.printStackTrace();
		}
		System.out.println("_______");
		try(MyResource myResource = new MyResource()){
			System.out.println("myResource");
		}
		catch(Exception e){
			e.printStackTrace();
		}
		System.out.println("_______");
		/*try(MyResourceWithOutAutoCloseable myResourceWithOutAutoCloseable = new MyResourceWithOutAutoCloseable()){
			System.out.println("myResource");
		}
		catch(Exception e){
			e.printStackTrace();
		}*/
		/*
		 * Exception in thread "main" java.lang.Error: Unresolved compilation problem: 
	The resource type MyResourceWithOutAutoCloseable does not implement java.lang.AutoCloseable
		 * */
		
		
	}
}

class MyResource implements AutoCloseable{
	@Override
	public void close() throws Exception {
		System.out.println("AutoCloseable");
	}
}

class MyResourceWithOutAutoCloseable{
	public MyResourceWithOutAutoCloseable() {
		System.out.println("constructor");
	}
}